import { createStore, combineReducers, applyMiddleware } from './redux'
// import thunk from 'redux-thunk'
const thunk = store => next => action => {
  //88888
  if (typeof action == 'function') {
    return action(next, store.getState)
  }
  return next(action)
}
const qqq = store => next => action => {
  console.log("qqq中间件执行了")
  return next(action)
}
const www = store => next => action => {
  console.log("www")
  return next(action)
}



function reducer(state, action) {
  // console.log(action)
  state = state || {
    count: 100
  }
  switch (action.type) {
    case 'add':
      return {
        ...state,
        count: state.count + action.num
      }
    case 'minus':
      return {
        ...state,
        count: state.count - action.num
      }
    default:
      return {
        ...state
      }
  }
}
function reducer2(state, action) {
  state = state || {
    color: 'red'
  }
  switch (action.type) {
    case 'changeColor':
      return {
        ...state,
        color: action.col
      }

    default:
      return {
        ...state
      }
  }
}

let rootReducer = combineReducers({
  A: reducer,
  B: reducer2
})
let store = createStore(rootReducer, applyMiddleware(qqq, thunk))
// {getState,subscribe,dispatch}
export default store